package ch.ethz.fcl.metrobuzz.render.custom;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.ArrayList;

import org.lwjgl.opengl.GL11;

import ch.ethz.fcl.metrobuzz.data.scene.MBScene;
import ch.ethz.fcl.metrobuzz.data.scene.basemap.Edge;
import ch.ethz.fcl.metrobuzz.data.scene.basemap.Node;
import ch.ethz.fcl.metrobuzz.render.techniques.vbo.ArrayBufferObject;

public class DefaultNetworkRenderer extends NetworkRenderer {
	protected ArrayBufferObject linkBuffer;

	public DefaultNetworkRenderer(MBScene scene, ArrayList<Node> nodes,
			ArrayList<Edge> links) {
		super(nodes, links);
		// load links
		ByteBuffer bb = ByteBuffer.allocateDirect(links.size() * 2 * 3 * 8);
		bb.order(ByteOrder.nativeOrder());
		FloatBuffer buffer = bb.asFloatBuffer();
		for (Edge edge : links) {
			Node from = nodes.get(edge.getStartNodeIndex());
			Node to = nodes.get(edge.getEndNodeIndex());
			buffer.put(from.getX());
			buffer.put(from.getY());
			buffer.put(0);
			buffer.put(to.getX());
			buffer.put(to.getY());
			buffer.put(0);
		}
		linkBuffer = new ArrayBufferObject();
		linkBuffer.load(buffer);
	}

	@Override
	public void render() {
		linkBuffer.draw(GL11.GL_LINES);
	}
}
